package com.zzq.controller;

import com.zzq.pojo.BidInfo;
import com.zzq.pojo.Result;
import com.zzq.pojo.vo.BidStatusUpdate;
import com.zzq.service.BidderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/bidderInfo")
@Slf4j
public class BidderInfoController {

    @Autowired
    private BidderInfoService bidderInfoService;

    /*
     * @Description: 参与投标
     * @Param: bidderInfo
     */
    @PostMapping("/add")
    public Result add(@RequestBody BidInfo bidderInfo){
        bidderInfoService.add(bidderInfo);
        return Result.success();
    }

    @GetMapping("/recommend")
    public Result<List<BidInfo>> recommend(String tenderer){
        ArrayList<BidInfo> bidInfos=bidderInfoService.recommend(tenderer);
        return Result.success(bidInfos);
    }


    @PostMapping("/bidsToUpdate")
    public Result bidsToUpdate(@RequestBody List<BidStatusUpdate> updateData) {
        try {
            bidderInfoService.updateBidStatus(updateData);
            return Result.success("状态更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(500,"状态更新失败");
        }
    }
    @GetMapping("/myBidderInfo")
    public Result<List<BidInfo>> myBidderInfo(String name){
        List<BidInfo> bidInfos=bidderInfoService.myBidderInfo(name);
        return Result.success(bidInfos);
    }
}
